// https://leetcode.cn/problems/minimum-size-subarray-sum/

class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int sum = 0;
        int l = 0;
        int minLen = INT_MAX;
        for (int i = 0; i < nums.size(); ++i) {
            sum += nums[i];
            while (sum >= target) {
                minLen = min(minLen, i - l + 1);
                sum -= nums[l];
                ++l;
            }
        }
        return minLen == INT_MAX ? 0 : minLen;
    }
};